import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

public class LoginWindow {
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setText("学生管理系统 - 登录");
        shell.setSize(300, 200);
        shell.setLayout(null);

        Label userLabel = new Label(shell, SWT.NONE);
        userLabel.setText("用户名:");
        userLabel.setBounds(30, 30, 60, 20);

        Text username = new Text(shell, SWT.BORDER);
        username.setBounds(100, 30, 150, 20);

        Label passLabel = new Label(shell, SWT.NONE);
        passLabel.setText("密码:");
        passLabel.setBounds(30, 70, 60, 20);

        Text password = new Text(shell, SWT.BORDER | SWT.PASSWORD);
        password.setBounds(100, 70, 150, 20);

        Button loginButton = new Button(shell, SWT.PUSH);
        loginButton.setText("登录");
        loginButton.setBounds(60, 120, 60, 30);

        Button registerButton = new Button(shell, SWT.PUSH);
        registerButton.setText("注册");
        registerButton.setBounds(150, 120, 60, 30);

        loginButton.addListener(SWT.Selection, e -> {
            String user = username.getText();
            String pass = password.getText();
            if ("test".equals(user) && "123".equals(pass)) {
                shell.dispose();
                MainWindow.open(display);
            } else {
                MessageBox box = new MessageBox(shell, SWT.ICON_ERROR);
                box.setMessage("用户名或密码错误！");
                box.open();
            }
        });

        registerButton.addListener(SWT.Selection, e -> {
            RegisterWindow.open(display);
        });

        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) display.sleep();
        }
        display.dispose();
    }
}


